import React, { Component } from 'react'
import './alert.less'
export default class Alert extends Component {
    constructor() {
        super();
        this.state = {
            title: [],
            subType: '',
            time: 3,
        };
    }
    render() {
        let { title, subType } = this.state
        console.log(subType);
        return (
            <div className="commont_alert">
                <div className="commont_alertX iconfont icon-delete2"
                    onClick={() => { this.props.alertX() }}></div>
                <div className="commont_title">{title}</div>
                {/* <div className="commont_alertbtn">
                    <div onClick={() => { this.props.alertX() }}>取消</div>
                    <div onClick={() => { this.props.alertSub() }}>确认</div>
                </div> */}
                {subType ?
                    <div className="commont_alertbtn">
                        <div>{this.state.time}秒后关闭哦</div>
                    </div>
                    :
                    <div className="commont_alertbtn">
                        <div onClick={() => { this.props.alertX() }}>取消</div>
                        <div onClick={() => { this.props.alertSub() }}>确认</div>
                    </div>}

            </div>
        )
    }
    componentDidMount() {
        if (this.props.subType) {
            console.log(222);
            this.setState({ title: this.props.title, subType: this.props.subType })
            let time = 3;
            this.timer = setInterval(() => {
                time -= 1
                console.log(time);
                this.setState({ time })
                if (time < 1) {
                    this.props.alertX()
                    clearInterval(this.timer)
                }
            }, 1000);
        } else {
            this.setState({ title: this.props.title })
        }

    }
}
